home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 4 code / Poly. in Code Resources / Virtual WDEF / Windoid.cp < prev    next >
Encoding:
Text File  |  1990-05-19  |  3.4 KB  |  154 lines  |  [TEXT/MPS ]

  1. /*
  2.     Windoid.cp
  3.     
  4.     Class that implements a "windoid" floating palette type window.
  5.     
  6.     Superclass:  WindowDefinition.
  7.  */
  8.  
  9. #ifndef __WINDOID__
  10. #include "Windoid.h"
  11. #endif
  12.  
  13. #ifndef __TOOLUTILS__
  14. #include <ToolUtils.h>
  15. #endif
  16.  
  17. #ifndef __MEMORY__
  18. #include <Memory.h>
  19. #endif
  20.  
  21. void Windoid::CalcRgns()
  22. {
  23.     // compute the content region of the window.
  24.     Rect itsPortRect = itsWindow->port.portRect;
  25.     OffsetRect(&itsPortRect, -itsWindow->port.portBits.bounds.left, -itsWindow->port.portBits.bounds.top);
  26.     RectRgn(itsWindow->contRgn, &itsPortRect);
  27.  
  28.     // compute the struct region.
  29.     InsetRect(&itsPortRect, -1, -1);
  30.     itsPortRect.top -= 10;
  31.     RectRgn(itsWindow->strucRgn, &itsPortRect);
  32.     itsPortRect.left++; itsPortRect.top++;
  33.     OffsetRect(&itsPortRect, 1, 1);
  34.     RgnHandle tmpRgn = NewRgn();
  35.     RectRgn(tmpRgn, &itsPortRect);
  36.     UnionRgn(tmpRgn, itsWindow->strucRgn, itsWindow->strucRgn);
  37.     DisposeRgn(tmpRgn);
  38. }
  39.  
  40. void Windoid::DrawFrame()
  41. {
  42.     // remember current penstate.
  43.     PenState oldPen;
  44.     GetPenState(&oldPen);
  45.     
  46.     // compute "hot" rectangles.
  47.     CalcRects();
  48.     
  49.     // draw frame around content region.
  50.     PenSize(1, 1);
  51.     FrameRect(&itsFrame);
  52.     
  53.     // draw drop shadow.
  54.     MoveTo(itsFrame.left + 3, itsFrame.bottom);
  55.     LineTo(itsFrame.right, itsFrame.bottom);
  56.     LineTo(itsFrame.right, itsFrame.top - 9);
  57.  
  58.     // draw the drag bar.
  59.     Pattern itsDragBarPat;
  60.     unsigned long grayBits;
  61.     if(itsDragRect.left & 1)
  62.         grayBits = 0xAA00AA00;
  63.     else
  64.         grayBits = 0x55005500;
  65.     if(itsDragRect.top & 1)
  66.         grayBits >>= 8;
  67.     ((long*)itsDragBarPat)[0] = grayBits;
  68.     ((long*)itsDragBarPat)[1] = grayBits;
  69.     FillRect(&itsDragRect, itsDragBarPat);
  70.     FrameRect(&itsDragRect);
  71.  
  72.     // draw go-away box if there is one.
  73.     if (itsWindow->goAwayFlag) {
  74.         InsetRect(&itsGoAwayBox, -1, -1);
  75.         EraseRect(&itsGoAwayBox);
  76.         InsetRect(&itsGoAwayBox, 1, 1);
  77.         FrameRect(&itsGoAwayBox);
  78.     }
  79.     
  80.     // preserve old font settings.
  81.     short txFont = qd.thePort->txFont;
  82.     short txSize = qd.thePort->txSize;
  83.  
  84.     // set new font style.
  85.     TextFont(3);
  86.     TextSize(9);
  87.     
  88.     Rect txtRect = itsDragRect;
  89.     InsetRect(&txtRect, 0, 1);
  90.     HLock((Handle)itsWindow->titleHandle);
  91.     short itsWidth = StringWidth(*itsWindow->titleHandle);
  92.     txtRect.left += (itsFrame.right - itsFrame.left - itsWidth)/2 - 2;
  93.     txtRect.right = txtRect.left + itsWidth + 2;
  94.     EraseRect(&txtRect);
  95.     MoveTo(itsFrame.left + (itsFrame.right - itsFrame.left - itsWidth)/2, itsFrame.top - 1);
  96.     DrawString(*itsWindow->titleHandle);
  97.     HUnlock((Handle)itsWindow->titleHandle);
  98.     
  99.     TextFont(txFont);
  100.     TextSize(txSize);
  101.     
  102.     SetPenState(&oldPen);                // restore old penstate.
  103. }
  104.  
  105. void Windoid::DrawGoAwayBox()
  106. {
  107.     // compute "hot" rectangles.
  108.     CalcRects();
  109.     InvertRect(&itsGoAwayBox);
  110. }
  111.  
  112. void Windoid::DrawGIcon()
  113. {
  114. }
  115.  
  116. void Windoid::DrawGrowImage(Rect& growRect)
  117. {
  118. }
  119.  
  120. long Windoid::Hit(Point& whereHit)
  121. {
  122.     if(PtInRgn(whereHit, itsWindow->strucRgn)) {
  123.         // compute "hot" rectangles.
  124.         CalcRects();
  125.         if(PtInRect(whereHit, &itsDragRect)) {
  126.             if(PtInRect(whereHit, &itsGoAwayBox))
  127.                 return wInGoAway;
  128.             return wInDrag;
  129.         }
  130.         if(PtInRgn(whereHit, itsWindow->contRgn))
  131.             return wInContent;
  132.     }
  133.     return wNoHit;
  134. }
  135.  
  136. // private methods.
  137.  
  138. void Windoid::CalcRects()
  139. {
  140.     itsFrame = (**itsWindow->contRgn).rgnBBox;
  141.     InsetRect(&itsFrame, -1, -1);
  142.     
  143.     itsDragRect = itsFrame;
  144.     itsDragRect.bottom = itsDragRect.top + 1;
  145.     itsDragRect.top -= 10;
  146.     
  147.     if(itsWindow->goAwayFlag) {
  148.         itsGoAwayBox = itsDragRect;
  149.         itsGoAwayBox.left += 8;
  150.         itsGoAwayBox.top += 2;
  151.         itsGoAwayBox.right = itsGoAwayBox.left + 7;
  152.         itsGoAwayBox.bottom = itsGoAwayBox.top + 7;
  153.     }
  154. }